@extends('admin.master')

@section('page_header')
    <h1 class="page-title">
        <i class="voyager-person"></i>角色列表
        @if ($add_role)
        <a href="{{ route('role.add') }}" class="btn btn-success">
            <i class="voyager-plus"></i> 新增角色
        </a>
        @endif
    </h1>
    @stop

    @section('page_header_actions')

    @stop

    @section('content')
    <div class="page-content container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="panel panel-bordered">
                    <div class="panel-body">
                        <table id="dataTable" class="table table-hover">
                            <thead>
                                <tr>
                                    <th>角色名</th>
                                    <th>描述</th>
                                    <th class="actions">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach($roles as $data)
                                <tr>
                                    <td>{{$data->name}}</td>
                                    <td>{{$data->display_name}}</td>
                                    <td class="no-sort no-click">
                                        @if ($del_role)
                                        <div class="btn-sm btn-danger pull-right delete" data-id="{{ $data->id }}" id="delete-{{ $data->id }}">
                                            <i class="voyager-trash"></i> 删除
                                        </div>
                                        @endif
                                        @if ($edit_role)
                                        <a href="{{ route('role.add', $data->id) }}" class="btn-sm btn-primary pull-right edit">
                                            <i class="voyager-edit"></i> 编辑
                                        </a>
                                        @endif
                                        <a href="{{ route('role.view', $data->id) }}" class="btn-sm btn-warning pull-right">
                                            <i class="voyager-eye"></i> 查看详情
                                        </a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal modal-danger fade" tabindex="-1" id="delete_modal" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title"><i class="voyager-trash"></i>确认删除该角色？ </h4>
                </div>
                <div class="modal-body">
                    <p>删除该角色将删除该角色下的所有用户，请谨慎删除！！！</p>
                </div>
                <div class="modal-footer">
                    <form action="{{ route('role.delete') }}" id="delete_form" method="POST">
                        {{ method_field("DELETE") }}
                        {{ csrf_field() }}
                        <input type="submit" class="btn btn-danger pull-right delete-confirm"
                               value="删除 ">
                    </form>
                    <button type="button" class="btn btn-default pull-right" data-dismiss="modal">取消</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    @stop
    @section('javascript')
    <!-- DataTables -->
    <script>
        $('td').on('click', '.delete', function (e) {
            var form = $('#delete_form')[0];
            form.action = parseActionUrl(form.action, $(this).data('id'));
            $('#delete_modal').modal('show');
        });
        function parseActionUrl(action, id) {
            return action.match(/\/[0-9]+$/)
                    ? action.replace(/([0-9]+$)/, id)
                    : action + '/' + id;
        }
    </script>
@stop
